package com.zhiche.lisa.lspm.dao.mapper.carrier;


import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.zhiche.lisa.lspm.dao.model.carrier.CarrierInfo;
import com.zhiche.lisa.lspm.dao.model.carrier.bo.CarrierDriverBO;
import com.zhiche.lisa.lspm.dao.model.carrier.bo.CarrierInfoBO;
import com.zhiche.lisa.lspm.dao.model.carrier.bo.CarrierInfoLineBO;
import com.zhiche.lisa.lspm.dao.model.carrier.bo.CarrierTrailerBO;
import com.zhiche.lisa.lspm.vo.vehicle.CarrierInfoLineVO;
import com.zhiche.lisa.lspm.vo.vehicle.WeChatVehicle;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * <p>
 * 牵引车 Mapper 接口
 * </p>
 *
 * @author qichao
 * @since 2018-05-23
 */
public interface CarrierInfoMapper extends BaseMapper<CarrierInfo> {

    /**
     * 根据车牌号查询
     * @param plate
     * @return
     */
    CarrierInfoBO selectByPlate(@Param("plate") String plate);

    /**
     * 根据司机id获取
     * @param driverId
     * @return
     */
    CarrierInfoBO selectByDriverId(@Param("driverId") Long driverId);

    /**
     * 牵引车基础信息列表
     * @param page
     * @param ew
     * @return
     */
    List<CarrierInfoLineVO> carrierInfoLine(Page<CarrierInfoLineBO> page,
                                            @Param("ew") Wrapper<CarrierInfoLineBO> ew);

    /**
     * 认证的牵引车信息列表
     * @param page
     * @param ew
     * @return
     */
    List<CarrierInfoLineVO> authedCarrierInfoLine(Page<CarrierInfoLineBO> page,
                                                  @Param("ew") Wrapper<CarrierInfoLineBO> ew);

    /**
     * 批量更新状态
     * @param status
     * @param idList
     */
    void batchUpdateStatus(@Param("status") Integer status, @Param("idList") List<Long> idList);

    /**
     * 根据ID更新车辆状态
     * @param status
     * @param id
     * @return
     */
    Integer updateStatus(@Param("status") Integer status, @Param("id") Long id);


    /**
     * 根据承运商 id 批量更新状态
     * @param status
     * @param lspIdList
     */
    void batchUpdateStatusByLspId(@Param("authStatus") Integer authStatus, @Param("status") Integer status, @Param("lspIdList") List<Long> lspIdList);

    /**
     * 根据ID批量更新状态
     * @param authStatus
     * @param status
     * @param carrierIds
     */
    void batchUpdateAuthStatusByIds(@Param("authStatus") Integer authStatus, @Param("status") Integer status, @Param
            ("IdList") List<Long> carrierIds);

    /**
     * 根据承运商id数组获取底下的所有牵引车id
     * @param lspIdList
     * @return
     */
    List<Long> selectIdByLspIds(@Param("lspIdList") List<Long> lspIdList);

    /**
     * 更新车辆所属承运商
     * @param carrierInfo
     * @return
     */
    Integer updateLsp(CarrierInfo carrierInfo);

    /**
     * 更新车辆所属承运商并移除司机
     * @param carrierIds
     * @param targetLspId
     * @return
     */
    Integer updateLspAndRemoveDriver(@Param("carrierIds") List<Long> carrierIds,
                                     @Param("targetLspId") Long targetLspId);
    /**
     * 分页查询牵引车与挂车
     * @param page
     * @param ew
     * @return
     */
    List<CarrierTrailerBO> selectPageCarrierTrailer(Page<CarrierTrailerBO> page,
                                                    @Param("ew") Wrapper<CarrierTrailerBO> ew);

    List<CarrierDriverBO> listUsableCarrier(@Param("ew") Wrapper<CarrierDriverBO> ew);

    List<WeChatVehicle> selectPageVehicle(Page<WeChatVehicle> page,
                                          @Param("ew") Wrapper<WeChatVehicle> ew);

    WeChatVehicle selectVehicleById(@Param("id") Long id);

    List<CarrierInfo> selectCarrierNoTenant(@Param("ew") Wrapper<CarrierInfo> ew);
    /**
     * 恢复删除状态
     */
    void updateDeleteStatus(@Param("ew") Wrapper<CarrierInfo> ew);


    WeChatVehicle selectVehicleByCarrierIdOrTrailerId(@Param("id") Long id, @Param("trailerId") Long trailerId);

    /**
     * 根据车牌查询车辆相关信息
     */
    CarrierInfoLineVO getVehicleByPlateNotenant(@Param("plate") String plate);

    WeChatVehicle selectVehicleByCTNoTenant(@Param("id")Long id,@Param("trailerId") Long tid);

    List<WeChatVehicle> selectVehicleByCarrierIdOrTrailerIdNoTenant(@Param("id")Long id,@Param("trailerId") Long tid);

    CarrierInfoBO selectByDriverIdNoTenant(@Param("driverId") Long driverId);
}
